package controller;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;

import javax.swing.JTable;

import model.FileTableModel;
import model.SearchTableModel;

import view.MainFrame;

public class SearchMouseListener implements MouseListener {
	
	
	private MainFrame frame;
	public SearchMouseListener(MainFrame frame) {
		
		this.frame = frame;
	}
	
	
	@Override
	public void mouseClicked(MouseEvent arg0) {
		if (arg0.getClickCount() == 2) {
			int rowNumber = ((JTable)arg0.getSource()).getSelectedRow();
			File newFile = ((SearchTableModel)((JTable)arg0.getSource()).getModel()).getSelectedRow(rowNumber);
			if (!newFile.isDirectory()) {
				newFile = newFile.getParentFile();
			}
			
			((FileTableModel) frame.getMainPanel().getPrimary().getDiskContent().getTable().getModel()).Clear();
			((FileTableModel) frame.getMainPanel().getPrimary().getDiskContent().getTable().getModel()).Create(newFile);	
			((FileTableModel) frame.getMainPanel().getPrimary().getDiskContent().getTable().getModel()).fireTableDataChanged();
			
			frame.getMainPanel().getPrimary().getDiskContent().setActualFile(newFile);
			frame.getMainPanel().getPrimary().getRelativePath().setText(newFile.getAbsolutePath());
			frame.getMainPanel().getPrimary().setStatusBar(newFile);
			
		}
		
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

}
